home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekkan Dennou Club 140
/
Gekkan Dennou Club - 2000.1 Vol. 140 (Japan).7z
/
Gekkan Dennou Club - 2000.1 Vol. 140 (Japan) (Track 1).bin
/
tools
/
has060
/
has06087.lzh
/
HANOI.S
< prev
next >
Wrap
Text File
|
1994-09-15
|
2KB
|
152 lines
* ~~~~~~~~~~~~
* ~~~ ハノイの塔 ~~~
* ~~~~~~~~~~~~
*
* アセンブラでハノイの塔を解くためのプログラムです。
* .R 実行形式にして TYPE すると、解法が“図解”されます。
* 円盤の枚数は次の N で指定します。
N:=7
* 以下は、変更する必要はありません。
ESC:=27
put .macro c
.dc.b c
.endm
xline .macro n,c
.dcb.b n,c
.endm
clear .macro
.dc.b ESC,'*'
.endm
locate .macro x,y
.dc.b ESC,'=',' '+y,' '+x
.endm
windowx:=96
windowy:=31
disk:='%'
space:=' '
pole:='|'
base:='#'
core:=2
hat:=2
width:=N+core
center2:=windowx/2
center1:=center2-width*2
center3:=center2+width*2
left:=center1-width
right:=center3+width
top:=(windowy-N)/2-hat
bottom:=top+hat+N
clear
locate left,bottom
xline right-left+1,base
i:=1
.rept 3
j:=top
.rept bottom-top
locate center%i,j
put pole
j:=j+1
.endm
i:=i+1
.endm
number1:=N
number2:=0
number3:=0
i:=1
.rept N
size1%i:=width-i
locate center1-size1%i,bottom-i
xline size1%i*2+1,disk
i:=i+1
.endm
move_disk .macro a,b
p:=a
q:=b
i:=number%p
j:=bottom-i
.rept N-i+hat+1
locate center%p-size%p%i,j-1
xline size%p%i*2+1,disk
locate center%p-size%p%i,j
xline size%p%i,space
put pole
xline size%p%i,space
j:=j-1
.endm
j:=center%p-size%p%i
locate j,top-2
xline size%p%i*2+1,disk
locate j,top-1
xline size%p%i*2+1,space
.if center%p<center%q
.rept center%q-center%p
locate j+size%p%i*2+1,top-2
put disk
locate j,top-2
put space
j:=j+1
.endm
.else
.rept center%p-center%q
locate j-1,top-2
put disk
locate j+size%p%i*2,top-2
put space
j:=j-1
.endm
.endif
locate j,top-1
xline size%p%i*2+1,disk
locate j,top-2
xline size%p%i*2+1,space
locate j,top
xline size%p%i*2+1,disk
locate j,top-1
xline size%p%i*2+1,space
k:=number%q+1
j:=top+1
.rept N-k+hat
locate center%q-size%p%i,j
xline size%p%i*2+1,disk
locate center%q-size%p%i,j-1
xline size%p%i,space
put pole
xline size%p%i,space
j:=j+1
.endm
number%p:=number%p-1
number%q:=k
size%q%k:=size%p%i
.endm
hanoi .macro n,a,b,c
.if n>0
hanoi n-1,a,c,b
move_disk a,c
hanoi n-1,b,a,c
.endif
.endm
hanoi N,1,2,3
locate 0,bottom+2